package y2015.date1008am.线程倒计时关闭窗体;

import org.junit.jupiter.api.Test;

import javax.swing.*;
import java.awt.*;

public class Wincloseinsoon extends JFrame {

    /**
     *
     */
    private static final long serialVersionUID = 257734557279978283L;
    static Label label;

    public Wincloseinsoon() {
        label = new Label();
        Font font = new Font("黑体", Font.PLAIN, 30);
        label.setFont(font);
        setTitle("10s");
        setSize(300, 300);
        setLayout(new GridLayout());
        setLocationRelativeTo(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
    }

    @Test
    public void main() throws Exception {
        final Wincloseinsoon win = new Wincloseinsoon();
        new Thread() {
            int time = 10;

            @Override
            public void run() {
                while (true) {

                    win.add(label);
                    label.setText(Integer.toString(time));
                    time--;
                    if (time == -1) {
                        System.exit(0);
                    }
                    try {
                        sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }.start();
    }
}

